package pers.twm.mybatis.action;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;
import pers.twm.mybatis.ui.LogExecutor;


import java.util.Objects;

/**
 * @ClassName SqlLogAction
 * @Description TODO
 * @Author tianwanming
 * @Date 2023/2/27 15:32
 * @Version 1.0
 */
public class SqlLogAction extends DumbAwareAction {


    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        final Project project = e.getProject();
        if (Objects.isNull(project)) {
            return;
        }

        runExecutor(project);
    }

    public void runExecutor(Project project) {
        if (project == null) {
            return;
        }
        // 设置restart (再次执行这个action)
        Runnable rerun = () -> runExecutor(project);
        // 设置stop
//        Runnable stop = () -> MyProjectUtil.setRunning(project, "running", false);
//        MyProjectUtil.setRunning(project, "running", true);
        LogExecutor executor = new LogExecutor(project, rerun);
        executor.run();
    }
}
